package com.cuit.zuke.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cuit.zuke.common.util.Result;
import com.cuit.zuke.hotel.model.hotel.Hotel;
import com.cuit.zuke.hotel.vo.hotel.HotelQueryVo;
import com.cuit.zuke.order.model.entity.HotelOrder;
import com.cuit.zuke.order.model.vo.GoodsOrderQueryVO;
import com.cuit.zuke.order.model.vo.GoodsOrderVO;
import com.cuit.zuke.order.model.vo.HotelOrderQueryVO;
import com.cuit.zuke.order.model.vo.HotelOrderVO;
import com.cuit.zuke.order.service.HotelOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/order/hotel")
public class HotelOrderController {

    @Autowired
    private HotelOrderService hotelOrderService;

    /**
     * 带条件的分页查询
     * @param page
     * @param limit
     * @param hotelOrderQueryVO
     * @return
     */
    @GetMapping(value = "list/{page}/{limit}")
    public Result listHotelOrder(@PathVariable Integer page,
                                 @PathVariable Integer limit,
                                 HotelOrderQueryVO hotelOrderQueryVO){
        Page<HotelOrderVO> voPage = hotelOrderService.findByPage(page, limit, hotelOrderQueryVO);
        return Result.ok().put("data",voPage);
    }

    /**
     * 根据id删除订单
     * @param id
     * @return
     */
    @PostMapping(value = "deleteById")
    public Result deleteGoodsOrder(@RequestBody Long id){
        boolean flag = hotelOrderService.deleteById(id);
        if (flag){
            return Result.ok();
        }else {
            return Result.error("删除失败");
        }
    }

    @PostMapping(value = "createHotelOrder")
    public void createHotelOrder(HotelOrder hotelOrder){
        hotelOrder.setCreateTime(new Date());
        hotelOrder.setUpdateTime(new Date());
        hotelOrder.setIsDelete((byte)0);
        hotelOrderService.save(hotelOrder);
    }

}
